//
//  RecommendViewController.m
//  ShareYOU
//
//  Created by Suns孙泉 on 14/12/17.
//  Copyright (c) 2014年 ShareYOU. All rights reserved.
//

#import "RecommendViewController.h"
#import "ShakeToSelectViewController.h"
#import "SidebarViewController.h"

@interface RecommendViewController () <UIScrollViewDelegate>

@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIImageView *barImageView;
@property (nonatomic, retain) SidebarViewController *sidebarVC;

@end

@implementation RecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
    [self.view addSubview:self.scrollView];
    self.scrollView.contentSize = CGSizeMake(0, 3000);
    // 点击状态栏, 返回scrollView顶部
    self.scrollView.scrollsToTop = YES;
    self.scrollView.delegate = self;
    [_scrollView release];
    
    
    // 定位地区图片
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 200)];
    imageView.image = [UIImage imageNamed:@"buy.png"];
    imageView.backgroundColor = [UIColor blueColor];
    [self.scrollView addSubview:imageView];
    [imageView release];
    
    // 假的导航栏
    self.barImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 64)];
    self.barImageView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.barImageView];
    self.barImageView.alpha = 0;
    [_barImageView release];
    
    UIButton *shakeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shakeButton.frame = CGRectMake(320, 20, 60, 40);
    UIImage *shakeImage = [UIImage imageNamed:@"iconfont-ttpodicon.png"];
    [shakeButton setImage:shakeImage forState:UIControlStateNormal];
    [shakeButton addTarget:self action:@selector(shakeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shakeButton];
    
    UIButton *listButton = [UIButton buttonWithType:UIButtonTypeCustom];
    listButton.frame = CGRectMake(0, 20, 60, 40);
    UIImage *listImage = [UIImage imageNamed:@"iconfont-liebiao-5.png"];
    [listButton setImage:listImage forState:UIControlStateNormal];
    [listButton addTarget:self action:@selector(listButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:listButton];
    
    // 左侧边栏开始
    UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
    [panGesture delaysTouchesBegan];
    [self.view addGestureRecognizer:panGesture];
    
    self.sidebarVC = [[SidebarViewController alloc] init];
    [self.sidebarVC setBgRGB:0x000000];
    [self.view addSubview:self.sidebarVC.view];
    self.sidebarVC.view.frame  = self.view.bounds;
    // 左侧边栏结束
    
}

// 点击listButton
- (void)listButtonClicked:(UIButton *)button{
    
    [self.sidebarVC showHideSidebar];
    
}

// 滑动手势
- (void)panDetected:(UIPanGestureRecognizer*)recoginzer
{
    [self.sidebarVC panDetected:recoginzer];
}

// 跳转摇一摇页
- (void)shakeButtonClicked:(UIButton *)button{
    
    ShakeToSelectViewController *shakeVC = [[ShakeToSelectViewController alloc] init];
    [self.navigationController pushViewController:shakeVC animated:NO];
    
}

// scrollview滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (self.scrollView.contentOffset.y <= 200) {
        
            // 随着scrollView的滚动透明度降低至1
        self.barImageView.alpha = self.scrollView.contentOffset.y / 200;
        
    }
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    // 将导航栏隐藏
    self.navigationController.navigationBarHidden = YES;
    
}

- (void)dealloc
{
    [_scrollView release];
    [_barImageView release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
